/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.topic.impl;

import java.util.List;

import org.grayrabbit.cms.dao.topic.TopicContentDao;
import org.grayrabbit.cms.entity.OperLog;
import org.grayrabbit.cms.entity.TopicContent;
import org.grayrabbit.cms.service.topic.TopicContentService;
import org.grayrabbit.cms.vo.topic.TopicContentBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：





 * @version 1.0,创建时间: 2011-06-02 12:39:24  
 */
@Service
@Transactional
public class TopicContentServiceImpl extends GenericServiceImpl implements TopicContentService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("topicContentDaoImpl")
	private TopicContentDao topicContentDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see TopicContentService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public TopicContent getTopicContent(final String id){
		TopicContent topicContent = topicContentDao.findById(id);
		topicContentDao.initialize(topicContent);
		return topicContent;
	}
	
	/**
	 * @see TopicContentService#delete(String)
	 */
	@Transactional
	public void delete(final TopicContent topicContent) {
		topicContentDao.makeTransient(topicContent);
	}
	
	/**
	 * @see TopicContentService#save(OperLog)
	 */
	@Transactional
	public void save(final TopicContent topicContent) {
		topicContentDao.makePersistent(topicContent);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see TopicContentService#getPage(TopicContentBean)
	 */
	@Transactional(readOnly=true)
	public Page<TopicContent> getPage(final TopicContentBean topicContentBean){
		Page<TopicContent> page =  new Page<TopicContent>();
		page.setTotal(topicContentDao.count(topicContentBean));
		page.setResult(topicContentDao.findByQc(topicContentDao.assembly(topicContentBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see TopicContentService#list(Page, TopicContentBean)
	 */
	public void list(Page<TopicContent> page, TopicContentBean topicContentBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(topicContentDao.count(topicContentBean));
		}
		page.setResult(topicContentDao.findByPage(page,topicContentBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see TopicContentService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			topicContentDao.makeTransient(topicContentDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				topicContentDao.clear();
		}
		
	}
	/**
	 * 根据专题id查询
	 */
 public List<TopicContent>findByTopicId(String topicId){
	 return topicContentDao.findByTopicId(topicId);
 }
}